// basicnpc.txt
// A very simple, naive text. Creature attacks anything it hates nearby.
// Once it has won, it returns to its home.
// Memory Cells:
//   Cell 0 - If 0, default behavior. If 1, it doesnt fidget.
//   Cell 1,2 - Stuff done flag. For activeness
//   Cell 3 - Number of state when talked to. Plays default text if 0.

begincreaturescript;

variables;

short i,target;
short following = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"Captain Addison");
	set_level(ME,22);
	set_boss_level(ME,0);
	sf(39,6,0);
	
	if (gf(39,4) != 1)
		erase_char(ME);
	if (gf(45,1) > 0)
		erase_char(ME);
	break;

beginstate DEAD_STATE;
	sf(45,1,1);
break;

beginstate START_STATE; 

		
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}

	if ((gf(39,6) > 0) && (gf(39,5) == 0) && (char_ok(8))) {
		if (can_see_char(8)) {
			sf(39,5,1);
			begin_talk_mode(42);
			}
		}
	if ((gf(39,1) == 2) && (gf(39,5) > 0)) {
		sf(39,4,2);
		begin_talk_mode(47);
		}
		
	if (gf(39,6) > 0) {
		if (dist_to_pc() > 12) {
			print_named_str(ME,"runs to catch up with you.");
			telep_char_to_char(ME,pc_num(),FALSE);
			}
			else maintain_dist_to_char(ME,pc_num(),2);
		}		
	
	
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking

	if (target_ok() == FALSE)
		set_state(START_STATE);
		
	do_attack();
break;

beginstate TALKING_STATE;
	if (gf(39,6) > 0) 
		begin_talk_mode(37);
		else begin_talk_mode(30);

break;